<?php
define("DATA_TABLE_NAME",'news2');
/**************** ACTION HANDER BEGIN *********************/
//修改数据
function save_block()
{
	if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0)
	{
		//update 
		$query = sprintf("UPDATE `%s` SET `content`='%s' WHERE `id`=%d",constant('DATA_TABLE_NAME'),addslashes($_REQUEST['content']),$_REQUEST['id']);
	}else{
		$query = sprintf("INSERT INTO `%s` SET `content`='%s',`newsid`=%d",constant('DATA_TABLE_NAME'),addslashes($_REQUEST['content']),$_REQUEST['articleID']);
	}
	$result=mysql_query($query);
	if($result == false)
		exit(sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__));
	
	return $result !== false;
}
// delete action
function delete_row_block()
{
	$id = $_REQUEST['id'];
	$query = sprintf("DELETE FROM `%s` WHERE `id`=%d",constant('DATA_TABLE_NAME'),$id);
	$result=mysql_query($query);
	if($result == false)
		exit(sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__));
}
/**************** ACTION HANDER END *********************/

function get_article_info($articleid)
{
	$query = sprintf("SELECT * FROM `news` WHERE `id`=%d",$articleid);
	$result=mysql_query($query);
	if($result == false)
		exit(sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__));
	$info = array();
	if(($row = mysql_fetch_assoc($result)))
	{
		$info = $row;
	}
	return $info;
}
function get_aricle_pages($articleid)
{
	$query = sprintf("SELECT * FROM `%s` WHERE `newsid`=%d",constant('DATA_TABLE_NAME'),$articleid);
	$result=mysql_query($query);
	if($result == false)
		exit(sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__));
	$page_list = array();
	while(($row = mysql_fetch_assoc($result)))
	{
		$page_list[] = $row;
	}
	return $page_list;
}

function get_article_page_info($id)
{
		$query = sprintf("SELECT `id`,`title`,`content` FROM `%s` WHERE `id`=%d",constant('DATA_TABLE_NAME'),$id);
	$result=mysql_query($query);
	if($result == false)
		exit(sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__));
	$info = array();
	if(($row = mysql_fetch_assoc($result)))
	{
		$info = $row;
	}
	return $info;
}
?>